home *** CD-ROM | disk | FTP | other *** search
/ APC & TCP 4 / APC & TCP 4.iso / games / publicdomain / a / asteroids2 / rotx / explosion.c < prev    next >
C/C++ Source or Header  |  1995-07-20  |  5KB  |  268 lines

  1. #include <exec/types.h>
  2. #include <intuition/intuition.h>
  3. #include <graphics/gfxmacros.h>
  4. #include <stdio.h>
  5. #include <h/rot.h>
  6. #include <h/extern.h>
  7.  
  8.  
  9. AllocateExplosion(xx,yy,length)
  10. LONG xx,yy,length;
  11. {
  12. LONG x,num=-1;
  13.  
  14. for(x=0;x<control.explosionnum;x++)
  15.     if (e[x].flag == FALSE)
  16.         {
  17.         num = x;
  18.         break;
  19.         }
  20.  
  21. if (num != -1)
  22.     {
  23.     e[num].x = xx;
  24.     e[num].y = yy;
  25.     e[num].frame = 0;
  26.     e[num].length  = length;
  27.     e[num].flag = TRUE;
  28.     }
  29. }
  30.  
  31. DrawTokenExplosions()
  32. {
  33. LONG xx,yy,wo;
  34. LONG n,pic;
  35.  
  36. for (n=0;n<control.explosionnum;n++)
  37.     if (e[n].flag == TRUE)
  38.         {
  39.         pic = il.explosion + e[n].frame;
  40.         xx = e[n].x-id[pic].wi/2;
  41.         yy = e[n].y-id[pic].he/2;
  42.         wo = ((id[pic].wi-1)/16)+1;
  43.  
  44.         SetAPen(rp1[bit],1);
  45.         SetWrMsk(rp1[bit],0xfd);
  46.         BltTemplate(id[pic].data,0,wo*2,rp1[bit],xx,yy,id[pic].wi,id[pic].he);
  47.         }
  48. }
  49.  
  50.  
  51. EraseTokenExplosions()
  52. {
  53. LONG x1,y1,x2,y2;
  54. LONG n,pic;
  55.  
  56. SetWrMsk(rp1[1-bit],0xfd);
  57. for (n=0;n<control.explosionnum;n++)
  58.     if (e[n].flag != FALSE)
  59.         {
  60.         if (e[n].frame != 0)
  61.             {
  62.             pic = il.explosion + e[n].frame - 1;
  63.             x1 = e[n].x-id[pic].wi/2;
  64.             y1 = e[n].y-id[pic].he/2;
  65.             x2 = e[n].x+id[pic].wi/2;
  66.             y2 = e[n].y+id[pic].he/2;
  67.             RectFill(rp1[1-bit],x1,y1,x2,y2);
  68.             }
  69.  
  70.         if (e[n].flag == LAST) e[n].flag = FALSE;
  71.         else
  72.         if (++e[n].frame > e[n].length) e[n].flag = LAST;
  73.         }
  74. }
  75.  
  76.  
  77.  
  78.  
  79. IncreaseScore(n,inc)
  80. LONG n,inc;
  81. {
  82. LONG x,xx,offset;
  83. BYTE string[10];
  84.  
  85. if (control.game == 1)
  86.     {
  87.     if ((control.score[n]/30000)<((control.score[n]+inc)/30000))
  88.         {
  89.         IncreaseLives(n,1);
  90.         makesound(12,2);
  91.         }
  92.  
  93.     control.score[n]+=inc;
  94.     sprintf(string,"%d",control.score[n]);
  95.     }
  96. else
  97.     {
  98.     control.score[n]+=inc;
  99.     sprintf(string,"%d",control.score[n]);
  100.     }
  101.  
  102.  
  103. offset = 16*(gi.smallfontheight-2);
  104. for (x=0;x<2;x++)
  105.     {
  106.     SetAPen(rp1[x],0);
  107.     SetWrMsk(rp1[x],0xfe);
  108.  
  109.     if (n == 0) xx = gi.x1;
  110.     else        xx = gi.wi/2;
  111.     RectFill(rp1[x],xx+offset-1,gi.he-2*(gi.smallfontheight+1)-1,
  112.                  xx+offset+8*(gi.smallfontheight-2),gi.he-gi.smallfontheight-2);
  113.  
  114.     SetAPen(rp1[x],2);
  115.     Move(rp1[x],xx+offset,gi.he-gi.smallfontheight-3);
  116.     Text(rp1[x],string,strlen(string));
  117.     }
  118. }
  119.  
  120. IncreaseLives(n,inc)
  121. LONG n,inc;
  122. {
  123. LONG x,xx,offset;
  124. BYTE string[10];
  125.  
  126. control.lives[n]+=inc;
  127. sprintf(string,"%d",control.lives[n]);
  128.  
  129. offset = 16*(gi.smallfontheight-2);
  130. for (x=0;x<2;x++)
  131.     {
  132.     SetWrMsk(rp1[x],0xfe);
  133.     SetAPen(rp1[x],0);
  134.  
  135.     if (n == 0) xx = gi.x1;
  136.     else        xx = gi.wi/2;
  137.     RectFill(rp1[x],xx+offset-1,gi.he-gi.smallfontheight-1,
  138.                      xx+offset+3*(gi.smallfontheight-2),gi.he-1);
  139.  
  140.     SetAPen(rp1[x],2);
  141.     Move(rp1[x],xx+offset,gi.he-1);
  142.     Text(rp1[x],string,strlen(string));
  143.     }
  144. }
  145.  
  146. IncreaseShields(n,dam)
  147. LONG n,dam;
  148. {
  149. LONG x,xx,offset;
  150. BYTE string[10];
  151.  
  152. ship[n].shield+=dam;
  153. sprintf(string,"%d",ship[n].shield);
  154.  
  155.  
  156. offset = 16*(gi.smallfontheight-2);
  157. for(x=0;x<2;x++)
  158.     {
  159.     SetWrMsk(rp1[x],0xfe);
  160.     SetAPen(rp1[x],0);
  161.  
  162.     if (n == 0) xx = gi.x1;
  163.     else        xx = gi.wi/2;
  164.     RectFill(rp1[x],xx+offset-1,2,
  165.                  xx+offset+5*(gi.smallfontheight-2),gi.smallfontheight+3);
  166.  
  167.     SetAPen(rp1[x],2);
  168.     Move(rp1[x],xx+offset,gi.smallfontheight+2);
  169.  
  170.     if (ship[n].shield < 0)    Text(rp1[x],"DEST",4);
  171.     else                    Text(rp1[x],string,strlen(string));
  172.     }
  173. }
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180. AllocateBoxes(xx,yy,max)
  181. LONG xx,yy,max;
  182. {
  183. LONG x,num=-1,random;
  184. LONG n;
  185.  
  186. if (control.game != 1)
  187. for(n=0;n<max;n++)
  188. {
  189. for(x=0;x<control.boxnum;x++)
  190.     if (b[x].length == 0)
  191.         {
  192.         num = x;
  193.         break;
  194.         }
  195.  
  196. if (num != -1)
  197.     {
  198.     random = Random(100.0);
  199.  
  200.     if (random > 90) /* extra life */
  201.         {
  202.         b[num].type = 0;
  203.         b[num].image = il.diamond;
  204.         b[num].rots = 31;
  205.         }
  206.     else
  207.     if (random > 70)  /* weapon */
  208.         {
  209.         b[num].type = 1;
  210.         b[num].image = il.box;
  211.         b[num].rots = 15;
  212.         }
  213.     else
  214.     if (random > 50)  /* autofire */
  215.         {
  216.         b[num].type = 3;
  217.         b[num].image = il.rectangle;
  218.         b[num].rots = 15;
  219.         }
  220.     else              /* shield */
  221.          {
  222.         b[num].type = 2;
  223.         b[num].image = il.triangle;
  224.         b[num].rots = 15;
  225.         }
  226.  
  227.     b[num].length = 100;
  228.     b[num].x = xx + Random(20.0)-10;
  229.     b[num].y = yy + Random(16.0)-8;
  230.     }
  231. }
  232. }
  233.  
  234.  
  235. UpdateBoxes()
  236. {
  237. LONG pic;
  238. LONG n;
  239.  
  240. for(n=0;n<control.boxnum;n++)
  241.     {
  242.     if (b[n].length > 2)
  243.         {
  244.         CollisionBoxShips(n);
  245.  
  246.         if (++b[n].pos > b[n].rots) b[n].pos = 0;
  247.         pic = b[n].image+b[n].pos;
  248.  
  249.         SetAPen(rp1[bit],1);
  250.         SetWrMsk(rp1[bit],0xfd);
  251.         BltTemplate(id[pic].data,0,2*id[pic].wo,rp1[bit],b[n].x,b[n].y,id[pic].wi,id[pic].he);
  252.         }
  253.     }
  254. }
  255.  
  256. EraseBoxes()
  257. {
  258. LONG n;
  259.  
  260. for (n=0;n<control.boxnum;n++)
  261.     if (b[n].length != 0)
  262.         {
  263.         SetWrMsk(rp1[1-bit],0xfd);
  264.         RectFill(rp1[1-bit],b[n].x,b[n].y,b[n].x+id[b[n].image].wi,b[n].y+id[b[n].image].he);
  265.         b[n].length--;
  266.         }
  267. }
  268.